package com.tg.app.adapter;

import android.content.Context;
import android.content.Intent;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.appbase.custom.config.ApiUrl;
import com.tg.app.R;
import com.tg.app.activity.WebActivity;
import com.appbase.custom.base.NoviceGuideBean;
import com.tg.appcommon.android.LanguageUtils;
import com.tg.app.view.CustomRoundAngleImageView;
import com.tange.core.backend.service.api.CoreApiUrl;

import java.util.List;

/**
 * Describe:
 * Created by Rance Rang on 2019-09-21.
 * <p>
 * Copyright (c) Tange.Inc All rights reserved.
 */
public class NoviceGuideAdapter extends RecyclerView.Adapter<NoviceGuideAdapter.NoviceGuideViewHolder> {
    private  Context context;
    private List<NoviceGuideBean>  noviceGuideBeanList;
    public   NoviceGuideAdapter(Context context,List<NoviceGuideBean>  noviceGuideBeanList){
        this.context = context;
        this.noviceGuideBeanList  = noviceGuideBeanList;
    }
    @NonNull
    @Override
    public NoviceGuideViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View  view  = LayoutInflater.from(this.context).inflate(R.layout.novice_guide_item,null);
        return new NoviceGuideViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NoviceGuideViewHolder noviceGuideViewHolder, final int i) {
        final NoviceGuideBean bean  =noviceGuideBeanList.get(i);
        if (bean==null)return;
        noviceGuideViewHolder.imageView.setImageResource(bean.imgResId);
        noviceGuideViewHolder.textView.setText(bean.title);
        noviceGuideViewHolder.relativeLayout.setClickable(true);
        noviceGuideViewHolder.relativeLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent  intent = new Intent(context, WebActivity.class);
                String url = String.format("%s%s?videoName=%s_v2.mp4&language=%s", CoreApiUrl.TG_HOST,ApiUrl.GUIDE_VIDEO,bean.tag, LanguageUtils.getLanguage(context));
                intent.putExtra(WebActivity.KEY_WEBURL,url);
                context.startActivity(intent);
            }
        });

    }


    @Override
    public int getItemCount() {
        return this.noviceGuideBeanList.size();
    }
    public class NoviceGuideViewHolder extends RecyclerView.ViewHolder{
        CustomRoundAngleImageView  imageView;
        RelativeLayout   relativeLayout;
        TextView  textView;

        public NoviceGuideViewHolder(@NonNull View itemView) {
            super(itemView);
            relativeLayout  = itemView.findViewById(R.id.rl_novice_guide);
            imageView = itemView.findViewById(R.id.iv_novice_gudie_item_img);
            textView = itemView.findViewById(R.id.tv_novice_gudie_item_name);
        }
    }
}
